﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IRPG
{
    //public delegate void NotifyHandler();
    public class Monster //不加修饰符默认的是internal类型的,当你不加时有其他public类的方法调用该类型的参数会报错：可访问性低。
    {
        
        public string Name
        {
            get;
            set;
        }
        public int HP
        {
            get;
            set;
        }
        public Monster(string name, int hp)
        {
            Name = name;
            HP = hp;
        }
        //public void Notify()
        //{
        //    if (HP <= 0)
        //        Console.WriteLine("怪物已死亡");
        //}
        /// <summary>
        /// 责任明确化，把责任抛给被对象，提高内聚性，目前是很流行“被XX”的！
        /// </summary>
        /// <param name="loss"></param>
        public void Notify(int loss)
        {
            if (HP <= 0)
            {
                Console.WriteLine("怪物已死亡");
                return;
            }
            HP -= loss;
            if (HP <= 0)
            {
                Console.WriteLine("攻击成功！怪物" + this.Name + "已死亡");
                return;
            }
            else
            {
                Console.WriteLine("攻击成功！怪物"+ this.Name +"损失了"+ loss +"HP");
            }
        }
    }
}
